package com.fare.taluo.base.struts2.json;

import java.io.IOException;

import net.sf.json.JSONSerializer;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.json.annotations.JSON;

import com.fare.taluo.base.struts2.BaseConventionStrutsAction;

/**
 * JSON的请求基类
 * @author xiangsf 2013-04-27
 *
 */
public abstract class BaseJsonStrutsAction extends BaseConventionStrutsAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2992755555764979288L;
	
	protected JsonReturnBean returnBean;
	
	@JSON(name="rbean")
	public JsonReturnBean getReturnBean() {
		return returnBean;
	}
	/**
	 * 本地的写JSON字符串返回
	 * @throws IOException
	 */
	public void writeJson() throws IOException{
		response.setContentType("utf-8");
		response.getWriter().print(JSONSerializer.toJSON(returnBean).toString());
	}
	
	/**
	 * 本地的写JSON字符串返回
	 * @throws IOException
	 */
	public void writeJson(Object obj) throws IOException{
		response.setContentType("utf-8");
		response.getWriter().print(JSONSerializer.toJSON(obj).toString());
	}
}
